using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ClickNET;
using ClickNET.Imaging;

public partial class Index : ClickNET.Web.UI.Page
{
    private List<string> m_galleryFolders;
    private Gallery m_gallery;
    private string m_galleryFolder;

    private static readonly string s_galleryDirectory = Config.DefaultInstance.GetConfigString("gallery", "imageDirectory");

    protected void Page_Load(object sender, EventArgs e)
    {
        this.AddCssFile("viewgallery.css");

        this.ShowSearchBar = true;

        this.m_galleryFolder = Request.QueryString["gallery"];

        if (!String.IsNullOrEmpty(this.m_galleryFolder))
        {
            this.m_gallery = FileSystemGalleryManager.LoadGallery(this.m_galleryFolder);
            this.m_gallery.ProcessGalleryFolder();

            dlPictures.DataSource = this.m_gallery.Pictures;
            dlPictures.DataBind();

        }
        else
        {
            this.m_galleryFolders = new List<string>();
            string[] subdirectoryEntries = Directory.GetDirectories(Path.Combine(Config.DataDirectory, s_galleryDirectory));
            string[] pathArr = new string[32];
            foreach (string dir in subdirectoryEntries)
            {
                pathArr = dir.Split('\\');
                string folder = pathArr[pathArr.Length - 1];

                // strip .svn and other unix dirs
                if (!folder.StartsWith("."))
                    this.m_galleryFolders.Add(folder);
            }

            List<Gallery> galleries = new List<Gallery>();

            foreach (string gal in this.m_galleryFolders)
            {
                Gallery g = FileSystemGalleryManager.LoadGallery(gal);
                galleries.Add(g);
            }

            dlGalleries.DataSource = galleries;
            dlGalleries.DataBind();

        }
    }
}
